﻿using FingerTip.Sms.Aliyun.Helper;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Text;

namespace FingerTip.Sms.Aliyun
{
    public class AliyunSmsSetting:IAliyunSmsSetting
    {
        public AliyunSmsSetting() { }

        public AliyunSmsSetting(IConfigurationRoot configuration)
        {
            if (configuration["Sms:Aliyun:IsEnabled"] != null & Convert.ToBoolean(configuration["Sms:Aliyun:IsEnabled"]))
            {
                this.AccessKeyId = configuration["Sms:Aliyun:AccessKeyId"];
                this.AccessKeySecret = configuration["Sms:Aliyun:AccessKeySecret"];
                if (!configuration["Sms:Aliyun:RegionId"].IsNullOrWhiteSpace())
                    this.RegionId = configuration["Sms:Aliyun:RegionId"];
                if (!configuration["Sms:Aliyun:EndpointName"].IsNullOrWhiteSpace())
                    this.EndpointName = configuration["Sms:Aliyun:EndpointName"];
                if (!configuration["Sms:Aliyun:Domain"].IsNullOrWhiteSpace())
                    this.Domain = configuration["Sms:Aliyun:Domain"];
                if (!configuration["Sms:Aliyun:Product"].IsNullOrWhiteSpace())
                    this.Product = configuration["Sms:Aliyun:Product"];

                this.SignName = configuration["Sms:Aliyun:SignName"];
                if (!configuration["Sms:Aliyun:TemplateCode"].IsNullOrWhiteSpace())
                    this.TemplateCode = configuration["Sms:Aliyun:TemplateCode"];

                if (!configuration["Sms:Aliyun:TemplateParam"].IsNullOrWhiteSpace())
                    this.TemplateParam = configuration["Sms:Aliyun:TemplateParam"];
            }
        }

       public string AccessKeyId { get; set; }
       public string AccessKeySecret { get; set; }
        public string Domain { get; set; } = "dysmsapi.aliyuncs.com";
        public string EndpointName { get; set; } = "cn-hangzhou";
        public string Product { get; set; } = "Dysmsapi";
        public string RegionId { get; set; } = "cn-hangzhou";
       public string SignName { get; set; }
       public string TemplateCode { get; set; }
        public string TemplateParam { get; set; } = "{{\"code\":\"{0}\"}}";
        public string OutId { get; set; } = "NSP";
    }
}
